package demo3;

/*
题目描述
SalaryManager类管理计时工资，workHourList是历次工作的时长，hourlyRate是小时费率，计算计时工资有两种策略：

SaryComputerStrategyOne策略，累计工作时长*小时费率，若累计工作时长大于160，再乘以1.2

SaryComputerStrategyTwo策略，若单项工作时长大于40，则乘以1.2 ,累计后*小时费率

请完成SaryComputerStrategyOne SaryComputerStrategyTwo 两个策略并提交

class SalaryManager{

    private List<Double> workHourList=new ArrayList<Double>();

    private SaryComputerStrategy strage;

    private double hourlyRate;



    public void setHourlyRate(double hourlyRate) {

        this.hourlyRate = hourlyRate;

    }





    public void setStrage(SaryComputerStrategy strage) {

        this.strage = strage;

    }

    public void addWorkHour(double h){

        workHourList.add(h);

    }

    public double computerSalary(){

        return  strage.computerSalary(workHourList,hourlyRate);

    }

}

interface SaryComputerStrategy{

    double computerSalary(List<Double> list,double rate);



}



//完成SaryComputerStrategyOne 和 SaryComputerStrategyTwo 类并提交



public class Main {

    public static void main(String[] args){

        SalaryManager salaryManager=new SalaryManager();

        salaryManager.setHourlyRate(50);

        salaryManager.addWorkHour(52);

        salaryManager.addWorkHour(40.5);

        salaryManager.addWorkHour(38.5);

        salaryManager.addWorkHour(60);

        salaryManager.setStrage(new SaryComputerStrategyOne());

        System.out.println(salaryManager.computerSalary());

        salaryManager.setStrage(new SaryComputerStrategyTwo());

        System.out.println(salaryManager.computerSalary());

    }

}



输入描述
输入描述

输出描述
11460.0

11075.0

提示
//完成SaryComputerStrategyOne 和 SaryComputerStrategyTwo 类并提交

样例输入  复制  更多
样例输出
11460.0
11075.0
允许最长运行时间
1000ms
允许使用最大内存
64MB
 */

import java.util.ArrayList;
import java.util.List;

class SalaryManager{

    private List<Double> workHourList=new ArrayList<Double>();

    private SaryComputerStrategy strage;

    private double hourlyRate;



    public void setHourlyRate(double hourlyRate) {

        this.hourlyRate = hourlyRate;

    }





    public void setStrage(SaryComputerStrategy strage) {

        this.strage = strage;

    }

    public void addWorkHour(double h){

        workHourList.add(h);

    }

    public double computerSalary(){

        return  strage.computerSalary(workHourList,hourlyRate);

    }

}

interface SaryComputerStrategy{

    double computerSalary(List<Double> list,double rate);



}
class SaryComputerStrategyOne implements SaryComputerStrategy{

    @Override
    public double computerSalary(List<Double> list, double rate) {
        double sumHour = 0;
        double fee = 0;
        for (Double i:list
        ) {
            sumHour+=i;
        }
        if(sumHour >160){
            fee = sumHour*1.2 *rate;
        }else{
            fee = sumHour * rate ;
        }
        return fee;
    }
}

class SaryComputerStrategyTwo implements SaryComputerStrategy{

    @Override
    public double computerSalary(List<Double> list, double rate) {
        double sumHour = 0;
        double fee = 0;
        for (double i:list
             ) {
            if(i>40){
                i = i*1.2;
            }
            sumHour += i;
        }
        return sumHour*rate;
    }
}
public class Main {

    public static void main(String[] args){

        SalaryManager salaryManager=new SalaryManager();

        salaryManager.setHourlyRate(50);

        salaryManager.addWorkHour(52);

        salaryManager.addWorkHour(40.5);

        salaryManager.addWorkHour(38.5);

        salaryManager.addWorkHour(60);

        salaryManager.setStrage(new SaryComputerStrategyOne());

        System.out.println(salaryManager.computerSalary());

        salaryManager.setStrage(new SaryComputerStrategyTwo());

        System.out.println(salaryManager.computerSalary());

    }

}
